package com.guli.teacher.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guli.common.result.Result;
import com.guli.teacher.entity.EduChapter;
import com.guli.teacher.entity.EduCourse;
import com.guli.teacher.entity.vo.CourseWebVo;
import com.guli.teacher.entity.vo.OneChapter;
import com.guli.teacher.service.EduChapterService;
import com.guli.teacher.service.EduCourseService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/frontcourse")
@CrossOrigin
public class FrontCourseController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduChapterService chapterService;

    /**
     * 根据课程id查询课程详情
     *
     */
    @GetMapping("getFrontCourseInfo/{id}")
    public Result getFrontCourseInfo(@PathVariable String id){

        // 1 根据课程id查询基本信息
        CourseWebVo courseFrontInfo = courseService.getCourseInfoFrontId(id);

        // 2 根据课程id查询课程大纲（章节和小节）
        List<OneChapter> videoById = chapterService.getChapterAndVideoById(id);
        return Result.ok().data("courseFrontInfo", courseFrontInfo).data("chapterVideoList", videoById);
    }

    /**
     * 课程分页列表
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("getCourseFrontList/{page}/{limit}")
    public Result getCourseFrontList(@PathVariable Long page,
                                     @PathVariable Long limit){
        Page<EduCourse> pageCourse = new Page<>(page, limit);
        Map<String,Object> map = courseService.getFrontCourseList(pageCourse);

        return Result.ok().data(map);
    }

}
